<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\admin\service;

use think\Db;

class ApiService
{
    /**
     * 获取所有友情链接
     */
    public static function links($limit='', $type='')
    {
        $where = [
            'status'  => 1,
            'site_id' => get_site_id('cookie'),
        ];

        if( !empty($type) ){
            $where['type'] = $type;
        }

        $limit = empty($limit) ? '' : $limit ;

        $data = Db::name('link')
             -> where($where)
             -> order('list_order ASC')
             -> limit($limit)
             -> select();

        return $data;
    }

    /**
     * 获取所有幻灯片
     * @param $slideId
     * @return false|\PDOStatement|string|\think\Collection
     */
    public static function slides($slideId, $limit='')
    {   
        $where = [
            'id'          => $slideId,
            'status'      => 1,
            'delete_time' => 0,
            'site_id'     => get_site_id('cookie'), //站点ID
        ];

        $slideCount = Db::name('slide')
                   -> where($where)
                   -> count();

        if ($slideCount == 0) {
            return [];
        }


        $where = [
            'slide_id' => $slideId,
            'status'   => 1,
            'site_id'  => get_site_id('cookie'),    //站点ID
        ];

        $limit = $limit == '-1'? '' : $limit;

        $slides = Db::name('slide_item')
               -> where($where)
               -> order('list_order ASC')
               -> limit($limit)
               -> select();

        return $slides;
    }
}
